package com.shuorikeji.huohuo.mvp;

import com.shuorikeji.huohuo.http.RetrofitUtils;
import com.shuorikeji.huohuo.utils.BusinessUtils;

import java.util.HashMap;
import java.util.Map;

import rx.Observable;

public class AllModel extends AllContract.IAllModel {
    /**
     * 获取二级分类
     *
     * @param flag       1传id
     * @param channel_id 一级分类id
     * @return data
     */
    @Override
    Observable<String> getSecFl(int flag, int channel_id) {
        Map<String, Object> map = new HashMap();
        if (flag == 1) {
            map.put("channel_id", channel_id);
        }
        return io_main(RetrofitUtils.getService().getSecFl(map));
    }

    @Override
    Observable<String> getTjBook(int page, int limit, int channel) {
        Map<String, Object> map = new HashMap();
        map.put("page", page);
        map.put("limit", limit);
        map.put("channel", channel);
        return io_main(RetrofitUtils.getService().getTjBook(map));
    }

    /**
     * 获取所有书籍
     *
     * @param flag      1新书严选
     *                  2潜力新书
     *                  3新书首发
     *                  5banner
     *                  4精选
     *                  6完结甄选
     *                  7热门标签书籍
     *                  8会员书库
     *                  9大家都在看
     *                  10搜索
     *                  11同一作者
     *                  12相似性
     *                  13会员分类页-书库
     *                  14rank获取所有书籍
     * @param sort      2新书首发 潜力新书（需要）
     * @param score     1潜力新书
     * @param banner    1=banner图返回
     * @param winnow    1=精选 0=普通
     * @param completed 2=完结 1=连载
     * @param is_vip    1=VIP书籍0=免费书籍
     * @return data
     */
    @Override
    Observable<String> getAllBook(int flag, int sort, int limit, int page,
                                  String search, int novel_channel_id, int novel_category_id,
                                  int is_hot, int tag_id, int completed, int is_vip, int word_num, int score,
                                  int winnow, int banner, String author, int subclassification_id) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        if (flag == 1 || flag == 3) {
            map.put("sort", sort);
        }
        if (flag == 2) {
            map.put("sort", sort);
            map.put("score", score);
        }
        if (flag == 4) {
            map.put("winnow", winnow);
        }
        if (flag == 5) {
            map.put("banner", banner);
        }
        if (flag == 6) {
            map.put("winnow", winnow);
            map.put("completed", completed);
        }
        if (flag == 7) {
            map.put("tag_id", tag_id);
        }
        if (flag == 8) {
            map.put("is_vip", is_vip);
        }
        if (flag == 9) {
            map.put("sort", sort);
            map.put("is_vip", is_vip);
        }
        if (flag == 10) {
            map.put("search", search);
        }
        if (flag == 11) {
            map.put("author", author);
        }
        if (flag == 12) {
            map.put("novel_category_id", novel_category_id);
        }
        if (flag == 13) {
            if (novel_channel_id != -1) {
                map.put("novel_channel_id", novel_channel_id);
            }
            if (novel_category_id != -1) {
                map.put("novel_category_id", novel_category_id);
            }
            if (is_hot != -1) {
                map.put("is_hot", is_hot);
            }
            if (completed != -1) {
                map.put("completed", completed);
            }
            if (word_num != -1) {
                map.put("word_num", word_num);
            }
            map.put("is_vip", is_vip);
        }
        if (flag == 14) {
            if (novel_channel_id != -1) {
                map.put("novel_channel_id", novel_channel_id);
            }
            if (novel_category_id != -1) {
                map.put("novel_category_id", novel_category_id);
            }
            if (subclassification_id != -1) {
                map.put("subclassification_id", subclassification_id);
            }
        }
        return io_main(RetrofitUtils.getService().getAllBook(map));
    }

    @Override
    Observable<String> cYouLike(int page, int limit) {
        Map<String, Object> map = new HashMap();
        map.put("page", page);
        map.put("limit", limit);
        return io_main(RetrofitUtils.getService().cYouLike(map));
    }

    @Override
    Observable<String> getHotTag() {
        return io_main(RetrofitUtils.getService().getHotTag());
    }

    @Override
    Observable<String> getUserInfo() {
        return io_main(RetrofitUtils.getService().getUserInfo());
    }

    /**
     * 获取小说评论列表
     *
     * @param flag 1获取全部
     *             2非全部
     * @return data
     */
    @Override
    Observable<String> getBookPl(int flag, int page, int novel_id, int limit, int is_new, int star) {
        Map<String, Object> map = new HashMap();
        map.put("novel_id", novel_id);
        map.put("page", page);
        map.put("limit", limit);
        map.put("is_new", is_new);
        if (flag == 2) {
            map.put("star", star);
        }
        return io_main(RetrofitUtils.getService().getBookPl(map));
    }

    /**
     * 获取小说详情
     *
     * @param id 期数
     * @return data
     */
    @Override
    Observable<String> getBookDetail(int id) {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        return io_main(RetrofitUtils.getService().getBookDetail(map));
    }

    /**
     * 添加书架
     *
     * @return data
     */
    @Override
    Observable<String> addSj(int novel_id) {
        Map<String, Object> map = new HashMap();
        map.put("novel_id", novel_id);
        return io_main(RetrofitUtils.getService().addSj(map));
    }

    /**
     * 获取小说评论列表
     *
     * @return data
     */
    @Override
    Observable<String> getBookZj(int page, int limit, int novel_id) {
        Map<String, Object> map = new HashMap();
        map.put("novel_id", novel_id);
        map.put("page", page);
        map.put("limit", limit);
        return io_main(RetrofitUtils.getService().getBookZj(map));
    }

    @Override
    Observable<String> login(String mobile, String code, String invite, String event) {
        Map<String, Object> map = new HashMap();
        map.put("mobile", mobile);
        map.put("code", code);
        map.put("event", event);
        if (!BusinessUtils.isEmpty(invite)) {
            map.put("invite", invite);
        }
        return io_main(RetrofitUtils.getService().login(map));
    }

    @Override
    Observable<String> getFontBg() {
        return io_main(RetrofitUtils.getService().getFontBg());
    }

    @Override
    Observable<String> setReadBg(int back_id) {
        Map<String, Object> map = new HashMap();
        map.put("back_id", back_id);
        return io_main(RetrofitUtils.getService().setReadBg(map));
    }

    @Override
    Observable<String> setFont(int font_id) {
        Map<String, Object> map = new HashMap();
        map.put("font_id", font_id);
        return io_main(RetrofitUtils.getService().setFont(map));
    }

    /**
     * 获取小说评论列表
     *
     * @return data
     */
    @Override
    Observable<String> getBookZjDetail(int novel_id, int chapter_id) {
        Map<String, Object> map = new HashMap();
        map.put("novel_id", novel_id);
        map.put("chapter_id", chapter_id);
        return io_main(RetrofitUtils.getService().getBookZjDetail(map));
    }

    /**
     * 添加评价
     *
     * @return data
     */
    @Override
    Observable<String> addReadHis(int chapter_id, int novel_id, int position) {
        Map<String, Object> map = new HashMap();
        map.put("chapter_id", chapter_id);
        map.put("novel_id", novel_id);
        map.put("position", position);
        return io_main(RetrofitUtils.getService().addReadHis(map));
    }

    @Override
    Observable<String> jbBookZj(String type, String content, int chapter_id) {
        Map<String, Object> map = new HashMap();
        map.put("type", type);
        if (!BusinessUtils.isEmpty(content)) {
            map.put("content", content);
        }
        map.put("chapter_id", chapter_id);
        return io_main(RetrofitUtils.getService().jbBookZj(map));
    }

    @Override
    Observable<String> getAllSort() {
        return io_main(RetrofitUtils.getService().getAllSort());
    }

    /**
     * 添加评价
     *
     * @return data
     */
    @Override
    Observable<String> plBook(int star, int novel_id, String content) {
        Map<String, Object> map = new HashMap();
        map.put("star", star);
        map.put("novel_id", novel_id);
        map.put("content", content);
        return io_main(RetrofitUtils.getService().plBook(map));
    }

    @Override
    Observable<String> getMh1Fl() {
        return io_main(RetrofitUtils.getService().getMh1Fl());
    }

    /**
     * @param flag 1根据一级分类
     * @return
     */
    @Override
    Observable<String> getAllMh(int flag, int sort, int limit, int page,
                                String search, String author, int novel_channel_id, int novel_category_id,
                                int is_hot, int tag_id, int completed, int is_vip, int word_num, int score,
                                int winnow, int banner) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        if (flag == 1) {
            map.put("cartoon_channel_id", novel_channel_id);
        } else if (flag == 2) {
            map.put("search", search);
        } else if (flag == 3) {
            map.put("author", author);
        } else if (flag == 4) {
            map.put("cartoon_channel_id", novel_channel_id);
            map.put("cartoon_category_id", novel_category_id);
        } else if (flag == 5) {
            map.put("winnow", winnow);
        } else if (flag == 6) {
            map.put("sort", sort);
            if (novel_channel_id != -1) {
                map.put("cartoon_channel_id", novel_channel_id);
            }
            if (novel_category_id != -1) {
                map.put("cartoon_category_id", novel_category_id);
            }
            map.put("is_hot", is_hot);
            if (completed != -1) {
                map.put("completed", completed);
            }
            map.put("score", score);
        }
        return io_main(RetrofitUtils.getService().getAllMh(map));
    }

    @Override
    Observable<String> getJxMh(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().getJxMh(map));
    }

    @Override
    Observable<String> mhSearchHistory() {
        return io_main(RetrofitUtils.getService().mhSearchHistory());
    }

    @Override
    Observable<String> bookSearchHistory() {
        return io_main(RetrofitUtils.getService().bookSearchHistory());
    }

    @Override
    Observable<String> deleteBookSearHis(int id) {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        return io_main(RetrofitUtils.getService().deleteBookSearHis(map));
    }

    @Override
    Observable<String> deleteMhSearHis(int id) {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        return io_main(RetrofitUtils.getService().deleteMhSearHis(map));
    }

    @Override
    Observable<String> mhHotSearch() {
        return io_main(RetrofitUtils.getService().mhHotSearch());
    }

    @Override
    Observable<String> bookHotSearch() {
        return io_main(RetrofitUtils.getService().bookHotSearch());
    }

    @Override
    Observable<String> getMhDetail(int id) {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        return io_main(RetrofitUtils.getService().getMhDetail(map));
    }

    @Override
    Observable<String> getMhZjList(int id, int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        map.put("id", id);
        return io_main(RetrofitUtils.getService().getMhZjList(map));
    }

    @Override
    Observable<String> getMhPlList(int cartoon_id, int is_new, int page, int limit) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        map.put("cartoon_id", cartoon_id);
        map.put("is_new", is_new);
        return io_main(RetrofitUtils.getService().getMhPlList(map));
    }

    @Override
    Observable<String> getMhZjDetail(int id, int chapter_id) {
        Map<String, Object> map = new HashMap();
        map.put("chapter_id", chapter_id);
        map.put("id", id);
        return io_main(RetrofitUtils.getService().getMhZjDetail(map));
    }

    @Override
    Observable<String> addMhPl(int star, int cartoon_id, String content) {
        Map<String, Object> map = new HashMap();
        map.put("cartoon_id", cartoon_id);
        map.put("content", content);
        map.put("star", star);
        return io_main(RetrofitUtils.getService().addMhPl(map));
    }

    @Override
    Observable<String> djTypeTree() {
        return io_main(RetrofitUtils.getService().djTypeTree());
    }

    @Override
    Observable<String> djList(int page, int limit, int channel, int cat_id, String keyword, String ym, int source) {
        Map<String, Object> map = new HashMap();
        map.put("page", page);
        map.put("limit", limit);
        map.put("channel", channel);
        map.put("cat_id", cat_id);
        map.put("keyword", keyword);
        map.put("ym", ym);
        map.put("source", source);
        return io_main(RetrofitUtils.getService().djList(map));
    }

    @Override
    Observable<String> djDetail(long id, int type, String csj) {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        map.put("type", type);
        if (type == 2) {
            map.put("csj", csj);
        }
        return io_main(RetrofitUtils.getService().djDetail(map));
    }

    @Override
    Observable<String> djDz(int vid, int mid) {
        Map<String, Object> map = new HashMap();
        map.put("vid", vid);
        map.put("mid", mid);
        return io_main(RetrofitUtils.getService().djDz(map));
    }

    @Override
    Observable<String> bookSjList(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().bookSjList(map));
    }

    @Override
    Observable<String> mhSjList(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().mhSjList(map));
    }

    @Override
    Observable<String> addMhSj(int cartoon_id) {
        Map<String, Object> map = new HashMap();
        map.put("cartoon_id", cartoon_id);
        return io_main(RetrofitUtils.getService().addMhSj(map));
    }

    @Override
    Observable<String> deleteMhSj(int id) {
        Map<String, Object> map = new HashMap();
        map.put("catoon_id", id);
        return io_main(RetrofitUtils.getService().deleteMhSj(map));
    }

    @Override
    Observable<String> addDeleteZj(int vid, int mid, long look_time) {
        Map<String, Object> map = new HashMap();
        map.put("vid", vid);
        map.put("mid", mid);
        map.put("look_time", look_time);
        return io_main(RetrofitUtils.getService().addDeleteZj(map));
    }

    @Override
    Observable<String> zjJlList(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().zjJlList(map));
    }

    @Override
    Observable<String> bookReadHis(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().bookReadHis(map));
    }

    @Override
    Observable<String> commonTask() {
        return io_main(RetrofitUtils.getService().commonTask());
    }

    @Override
    Observable<String> getAllReadSeeVideoCount() {
        return io_main(RetrofitUtils.getService().getAllReadSeeVideoCount());
    }

    @Override
    Observable<String> mhReadHis(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().mhReadHis(map));
    }

    @Override
    Observable<String> addMhReadHis(int cartoon_id, int chapter_id, int position) {
        Map<String, Object> map = new HashMap();
        map.put("cartoon_id", cartoon_id);
        map.put("chapter_id", chapter_id);
        map.put("position", position);
        return io_main(RetrofitUtils.getService().addMhReadHis(map));
    }

    @Override
    Observable<String> plAddBookSj(String novel_id) {
        Map<String, Object> map = new HashMap();
        map.put("novel_id", novel_id);
        return io_main(RetrofitUtils.getService().plAddBookSj(map));
    }

    @Override
    Observable<String> plDeleteBookHis(String id) {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        return io_main(RetrofitUtils.getService().plDeleteBookHis(map));
    }

    @Override
    Observable<String> plDeleteMhHis(String id) {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        return io_main(RetrofitUtils.getService().plDeleteMhHis(map));
    }

    @Override
    Observable<String> djSeeJl(long vl_id, int vid, long min) {
        Map<String, Object> map = new HashMap();
        map.put("vl_id", vl_id);
        map.put("vid", vid);
        map.put("min", min);
        return io_main(RetrofitUtils.getService().djSeeJl(map));
    }

    @Override
    Observable<String> djSeeJlList(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().djSeeJlList(map));
    }

    @Override
    Observable<String> plDelDjJl(String id) {
        Map<String, Object> map = new HashMap();
        map.put("ids", id);
        return io_main(RetrofitUtils.getService().plDelDjJl(map));
    }

    @Override
    Observable<String> seeMhSd(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().seeMhSd(map));
    }

    @Override
    Observable<String> mhHotTag(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().mhHotTag(map));
    }

    @Override
    Observable<String> addMhSd(String title, String content, String tags, int is_privacy, String img) {
        Map<String, Object> map = new HashMap();
        map.put("title", title);
        map.put("content", content);
        map.put("tags", tags);
        map.put("is_privacy", is_privacy);
        map.put("img", img);
        return io_main(RetrofitUtils.getService().addMhSd(map));
    }

    @Override
    Observable<String> myLikeDj(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().myLikeDj(map));
    }

    @Override
    Observable<String> myMsg(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().myMsg(map));
    }

    @Override
    Observable<String> userYjfk(String feedback, String report_type, int source, String imgurl, String mobile) {
        Map<String, Object> map = new HashMap();
        map.put("feedback", feedback);
        map.put("report_type", report_type);
        map.put("source", source);
        if (!BusinessUtils.isEmpty(imgurl)) {
            map.put("imgurl", imgurl);
        }
        map.put("mobile", mobile);
        return io_main(RetrofitUtils.getService().userYjfk(map));
    }

    @Override
    Observable<String> scMhSd(int book_list_id) {
        Map<String, Object> map = new HashMap();
        map.put("book_list_id", book_list_id);
        return io_main(RetrofitUtils.getService().scMhSd(map));
    }

    @Override
    Observable<String> qxScMhSd(int book_list_id) {
        Map<String, Object> map = new HashMap();
        map.put("book_list_id", book_list_id);
        return io_main(RetrofitUtils.getService().qxScMhSd(map));
    }

    @Override
    Observable<String> dzMhSd(int book_list_id) {
        Map<String, Object> map = new HashMap();
        map.put("book_list_id", book_list_id);
        return io_main(RetrofitUtils.getService().dzMhSd(map));
    }

    @Override
    Observable<String> qxDzMhSd(int book_list_id) {
        Map<String, Object> map = new HashMap();
        map.put("book_list_id", book_list_id);
        return io_main(RetrofitUtils.getService().qxDzMhSd(map));
    }

    @Override
    Observable<String> myScMhSd(int limit, int page) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().myScMhSd(map));
    }

    @Override
    Observable<String> mhSdDetail(int book_list_id) {
        Map<String, Object> map = new HashMap();
        map.put("book_list_id", book_list_id);
        return io_main(RetrofitUtils.getService().mhSdDetail(map));
    }

    @Override
    Observable<String> addMhToSd(int book_list_id, int cartoon_id) {
        Map<String, Object> map = new HashMap();
        map.put("book_list_id", book_list_id);
        map.put("cartoon_id", cartoon_id);
        return io_main(RetrofitUtils.getService().addMhToSd(map));
    }

    @Override
    Observable<String> delSdMh(int id) {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        return io_main(RetrofitUtils.getService().delSdMh(map));
    }

    @Override
    Observable<String> xgUserInfo(String avatar, String nickname) {
        Map<String, Object> map = new HashMap();
        map.put("avatar", avatar);
        map.put("nickname", nickname);
        return io_main(RetrofitUtils.getService().xgUserInfo(map));
    }

    @Override
    Observable<String> qbDsyMx() {
        return io_main(RetrofitUtils.getService().qbDsyMx());
    }

    @Override
    Observable<String> mhSdGc(int limit, int page, String hot, String news) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        if (!BusinessUtils.isEmpty(hot)) {
            map.put("hot", hot);
        }
        if (!BusinessUtils.isEmpty(news)) {
            map.put("news", news);
        }
        return io_main(RetrofitUtils.getService().mhSdGc(map));
    }

    @Override
    Observable<String> mhEjFl(int channel_id) {
        Map<String, Object> map = new HashMap();
        if (channel_id != -1) {
            map.put("channel_id", channel_id);
        }
        return io_main(RetrofitUtils.getService().mhEjFl(map));
    }

    @Override
    Observable<String> ztJl(int page, int limit) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().ztJl(map));
    }

    @Override
    Observable<String> tcLogin() {
        return io_main(RetrofitUtils.getService().tcLogin());
    }

    @Override
    Observable<String> zxZh() {
        return io_main(RetrofitUtils.getService().zxZh());
    }

    @Override
    Observable<String> mhCnLike(int page, int limit) {
        Map<String, Object> map = new HashMap();
        map.put("limit", limit);
        map.put("page", page);
        return io_main(RetrofitUtils.getService().mhCnLike(map));
    }

    @Override
    Observable<String> tx(double money, int send_type, int id, int type) {
        Map<String, Object> map = new HashMap();
        map.put("money", money);
        map.put("send_type", send_type);
//        if (send_type == 1) {
//            map.put("id", id);
//        }
        map.put("type", type);
        return io_main(RetrofitUtils.getService().tx(map));
    }

    @Override
    Observable<String> aliPaySq(String code) {
        Map<String, Object> map = new HashMap();
        map.put("code", code);
        return io_main(RetrofitUtils.getService().aliPaySq(map));
    }

    @Override
    Observable<String> getNewVersion() {
        return io_main(RetrofitUtils.getService().getNewVersion());
    }

    @Override
    Observable<String> getSeeAdCount() {
        return io_main(RetrofitUtils.getService().getSeeAdCount());
    }

    @Override
    Observable<String> getBookAdJl() {
        return io_main(RetrofitUtils.getService().getBookAdJl());
    }

    @Override
    Observable<String> getMhAdJl() {
        return io_main(RetrofitUtils.getService().getMhAdJl());
    }

    @Override
    Observable<String> djAdJsDj(int ad_id, int vl_id, int weigh, int type) {
        Map<String, Object> map = new HashMap();
        map.put("ad_id", ad_id);
        map.put("vl_id", vl_id);
        map.put("weigh", weigh);
        map.put("type", type);
        return io_main(RetrofitUtils.getService().djAdJsDj(map));
    }

    @Override
    Observable<String> jtJl() {
        return io_main(RetrofitUtils.getService().jtJl());
    }

    @Override
    Observable<String> allSeeAdDy(String source, String ecpm, int ad_source, String sdkName) {
        Map<String, Object> map = new HashMap();
        map.put("source", source);
        map.put("ecpm", ecpm);
        map.put("ad_source", ad_source);
        map.put("sdkName", sdkName);
        return io_main(RetrofitUtils.getService().allSeeAdDy(map));
    }

    @Override
    Observable<String> sendYzm(String mobile,String event) {
        Map<String, Object> map = new HashMap();
        map.put("mobile", mobile);
        map.put("event",event);
        return io_main(RetrofitUtils.getService().sendYzm(map));
    }
}
